package com.msds.parent.users.serviceimpl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.msds.parent.common.util.ConstatFinalUtil;
import com.msds.parent.persist.mapper.AAdminsMapper;
import com.msds.parent.persist.mapper.AUsersMapper;
import com.msds.parent.persist.po.AAdmins;
import com.msds.parent.persist.po.AUsers;
import com.msds.parent.persist.service.IUsersService;
@Service("usersService")
public class UsersServiceImpl implements IUsersService{
    @Resource
	private AAdminsMapper adminsmapper;
    @Resource
    private AUsersMapper usermapper;
	@Override
	public JSONObject saveOneAdminsService(AAdmins admins) {
		JSONObject resultJSON=new JSONObject();
		/**
		 * 影响调试
		 */
		int res=adminsmapper.insert(admins);
		if(res>0){
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
			
			/**
			 * 存储data数据
			 */
			JSONObject dataJSON=new JSONObject();
			dataJSON.put("id", admins.getId()+"");
			dataJSON.put("effect", res+"");
			dataJSON.put("data", dataJSON);
		}else{
			resultJSON.put("code", "1");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("1"));
		}
		return resultJSON;
	}

	@Override
	public JSONObject updateOneAdminsService(AAdmins admins) {
		JSONObject resultJSON=new JSONObject();
		int res=adminsmapper.updateByPrimaryKey(admins);
		if(res>0){
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
			/**
			 * 存储data数据
			 */
			JSONObject dataJSON=new JSONObject();
			dataJSON.put("id", admins.getId()+"");
			dataJSON.put("effect", res+"");
			dataJSON.put("data", resultJSON);
		}else{
		     resultJSON.put("code", "2");
		     resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("2"));
		}
		return resultJSON;
	}

	@Override
	public JSONObject deleteOneAdminsService(AAdmins admins) {
	    JSONObject resultJSON=new JSONObject();
	    int res=this.adminsmapper.updateByPrimaryKey(admins);
	    if(res>0){
	    	resultJSON.put("code", "0");
	        resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
	        /*存储数据*/
	        JSONObject dataJSON=new JSONObject();
	        dataJSON.put("id", admins.getId()+"");
	        dataJSON.put("effect", res+"");
	        dataJSON.put("data", resultJSON);
	    }else{
	    	resultJSON.put("code", "3");
	    	resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("3"));
	    }
		return resultJSON;
	}

	@Override
	public JSONObject saveOneAuserService(AUsers users)
	{
		JSONObject resultJSON=new JSONObject();
		/**
		 * 影响调试
		 */
		int res=usermapper.insert(users);
		if(res>0){
			resultJSON.put("code", "0");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("0"));
			
			/**
			 * 存储data数据
			 */
			JSONObject dataJSON=new JSONObject();
			dataJSON.put("id", users.getId()+"");
			dataJSON.put("effect", res+"");
			dataJSON.put("data", dataJSON);
		}else{
			resultJSON.put("code", "1");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("1"));
		}
		return resultJSON;
	}

}